﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace 服务器
{
    class message
    {
        byte[] data = new byte[1024];
        private int startindex = 0;
        public byte[] Data { get => data; set => data = value; }
        public int Startindex { get => startindex; set => startindex = value; } 
        public int remainsize {
            get { return data.Length - startindex; }
        }
        public void addcount(int count)
        {
            startindex += count;
        }
        public void getmessage()
        {
            while (true)
            {
              if (startindex<=4)
             {
                  return;
              }
              int length = BitConverter.ToInt32(data, 0);
                if (startindex - 4 >= length)
                {
                    string s = Encoding.UTF8.GetString(data, 4, length);
                    Console.WriteLine("接到客户端消息" + s);
                    Array.Copy(data, 4 + length, data, 0, startindex - 4 - length);
                    startindex -= (4 + length);
                }
                else
                {
                    break;
                }

            }
            
        }
    }
}
